package org.jradweb.tools.generator.maven;

/*
 * Copyright 2001-2005 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.maven.plugin.MojoExecutionException;
import org.jradweb.tools.generator.freemarker.ClassGenerator;
import org.jradweb.tools.generator.freemarker.DatasetGenerator;
import org.jradweb.tools.generator.xml.HibernateConfigOperator;
import org.jradweb.tools.generator.xml.SpringControllerConfigOperator;
import org.jradweb.tools.generator.xml.SpringServiceConfigOperator;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/**
 * generate dao, service,  controller and page from model
 *
 * Created On 2008-4-15
 * @author <a href="mailto:wagzhi@gmail.com">Paul Wang</a>
 * @version $Id: CreateDatasetMojo.java 100 2008-04-15 10:37:55Z wagzhi $
 * 
 * @goal createDataset
 */
public class CreateDatasetMojo
    extends BaseMojo
{
	
	
	
    public void doExecute()
        throws MojoExecutionException
    {
    	String modelName=System.getProperty("model");
    	
    	if(modelName==null){
    		throw new MojoExecutionException("Parameter model can not be null");
    	}
       
    	getLog().info("create dataset file from model "+modelName);
        getLog().info("groupId: "+groupId);
        getLog().info("artifactId: "+artifactId);
        getLog().info("rootPath: "+baseDir.getAbsolutePath());
        
       
        try {
			getLog().info("baseDir="+this.baseDir.getAbsolutePath());
			getLog().info("project="+this.project);
			getLog().info("buildDir="+this.buildPath);
			
			DatasetGenerator dg=new DatasetGenerator(this.baseDir,this.groupId,this.artifactId,this.getLog());
			dg.createDatasetFile(modelName);
		} catch (Exception e) {
			throw new MojoExecutionException(e.getMessage(),e);
		} 
    }
    
   
}
